package com.fz.controller.system;

import com.fz.aop.login.AnonymousAccess;
import com.fz.common.ResponseEntity;
import com.fz.beans.IdBeans;
import com.fz.beans.PageBeans;
import com.fz.dto.system.dictionary.DictAdd;
import com.fz.dto.system.dictionary.DictQuery;
import com.fz.dto.system.dictionary.DictUpd;
import com.fz.entity.system.Dictionary;
import com.fz.service.system.DictionaryService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Api(value = "字典管理", tags = "字典管理")
@RequestMapping("/dict")
@ApiSort(value = 8)
@CrossOrigin
@SuppressWarnings("unchecked")
public class DictionaryController {

    @Resource
    private DictionaryService dictionaryService;

    @GetMapping("/findDictList")
    @ApiOperation(value = "查询字典分页列表")
    @ApiOperationSupport(order = 1)
    @AnonymousAccess
    @ApiImplicitParams({
            @ApiImplicitParam(name = "desc", value = "描述", required = false, dataType = "String", paramType = "query")
    })
    public ResponseEntity<Dictionary> findDictList(String desc,PageBeans pageBeans) throws Exception {
        return dictionaryService.findDictList(desc, pageBeans.getPageSize(), pageBeans.getPageNum());
    }

    @PostMapping("/saveDict")
    @ApiOperation(value = "新增字典")
    @ApiOperationSupport(order = 2)
    @AnonymousAccess
    public ResponseEntity saveDict(@RequestBody DictAdd dictAdd) throws Exception {
        return dictionaryService.saveDict(dictAdd);
    }

    @PostMapping("/updateDict")
    @ApiOperation(value = "修改字典")
    @ApiOperationSupport(order = 3)
    @AnonymousAccess
    public ResponseEntity updateDict(@RequestBody DictUpd dictUpd) throws Exception {
        return dictionaryService.updateDict(dictUpd);
    }

    @PostMapping("/delDict")
    @ApiOperation(value = "删除字典")
    @ApiOperationSupport(order = 4)
    @AnonymousAccess
    public ResponseEntity delDict(@RequestBody IdBeans idBeans) throws Exception {
        return dictionaryService.delDict(idBeans.getIds());
    }

    @GetMapping("/findDictValueList")
    @ApiOperation(value = "查询字典以及字典值")
    @ApiOperationSupport(order = 5)
    public ResponseEntity findDictValueList(DictQuery dictQuery,PageBeans pageBeans) {
        return dictionaryService.findDictValueList(pageBeans.getPageNum(), pageBeans.getPageSize(), dictQuery);
    }
}
